import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { RemoveTableService } from 'app/public/serve/remove-table/remove-table.service';
import { HintsService } from 'app/public/serve/hints/hints.service';

import { terminalUrl } from '../terminal.url';
import { Service } from 'app/server/server';

@Component({
  selector: 'terminal-delete',
  templateUrl: './terminal-delete.component.html',
  styleUrls: ['./terminal-delete.component.css']
})
export class TerminalDeleteComponent implements OnInit {

  @Output() delete = new EventEmitter<void>();

  constructor(
    private request: RemoveTableService, 
    private hintsService: HintsService,
    public server: Service,
  ) {}

  ngOnInit() {
  }

  /**
   * 删除
   */ 
  _delete() {
  	this.request
        .confirmRemove('terminalId', this.server.baseUrl + terminalUrl.delete)
        .then(res =>{
          if (res.result_code=='0000') {
            this.delete.emit();
          }
          this.hintsService._operationHints(res.message, res.result_code);
          return
        })
        .catch(err => {
          this.hintsService._operationHints('error', 'error');
          return
        })
  }

}
